package com.damai.mvc.view.imple;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.http.HttpServletResponse;

import com.damai.mvc.view.View;

public class BytesView implements View {

	private byte[] bytes;
	private String name;

	public BytesView(byte[] bytes,String name) {
		this.bytes = bytes;
		this.name = name;
	}

	@Override
	public void renderTo(HttpServletResponse response) throws IOException {
		response.setHeader("content-disposition", "attachment; filename=" + URLEncoder.encode(name, "utf-8"));
		response.getOutputStream().write(bytes);
		response.getOutputStream().close();
	}

}
